<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

if (!function_exists('get_field_producto')) {

    function get_field_producto($field = null, $value = null) {
        $CI = & get_instance();
        $CI->config->load('database_tables');
        $total_tables = $CI->config->item('dbtables');
        $cadena = "";
        switch ($field) {
            case 'descripcion':
            case 'direccion':
            case 'codigopostal':
            case 'web':
            case 'barrio':
                return '<input value="'.$value.'" type="text" name="' . $field . '" 
                        id="' . $field . '"/>';
                break;
            case 'piso':
                return '<input value="'.$value.'" type="text" style="width: 200px" name="' . $field . '" 
                        id="' . $field . '"/>';
                break;
            case 'ultima_reforma':
            case 'antiguedad':
                return '<span><input value="'.($value == null ? '1950' : $value).'" maxlength="4" 
                class="class_input_date spin_input sizew70" type="text" name="' . $field . '" 
                id="' . $field . '" style="margin-right: 0px; padding-right: 0px;"/></span>';
                break;
            case 'numero':
                return '<span><input value="'.($value == null ? '0' : $value).'" maxlength="4" 
                class="class_input_spin spin_input sizew30" type="text" name="' . $field . '" 
                id="' . $field . '" style="margin-right: 0px; padding-right: 0px;"/></span>';
                break;
            case 'importe_limpieza':
                return '<span><input value="'.($value == null ? '0' : $value).'" maxlength="4" 
                class="class_input_spin spin_input sizew30" type="text" name="' . $field . '" 
                id="' . $field . '" style="margin-right: 0px; padding-right: 0px;"/>&nbsp;€</span>';
                break;
            case 'porcentaje_fianza':
                return '<span><input value="'.($value == null ? '0' : $value).'" maxlength="4" 
                class="class_input_spin spin_input sizew30" type="text" name="' . $field . '" 
                id="' . $field . '" style="margin-right: 0px; padding-right: 0px;"/>&nbsp;%</span>';
                break;
            case 'fk_id_producto_tipo':
                $query = $CI->db->get($total_tables['producto_tipo']);
                $cadena = "<select name='" . $field . "' id='" . $field . "'>";
                foreach ($query->result_array() as $row) {
                    $cadena .= "<option value='" . $row['id'] . "'>" . $row['descripcion'] . "</option>";
                }
                $cadena .= "</select>";
                return $cadena;
                break;
            case 'fk_id_provincia':
                $query = $CI->db->get($total_tables['provincias']);
                $cadena = "<select name='" . $field . "' id='" . $field . "'>";
                foreach ($query->result_array() as $row) {
                    $cadena .= "<option value='" . $row['id'] . "'>" . $row['nombre'] . "</option>";
                }
                $cadena .= "</select>";
                return $cadena;
                break;
            case 'fk_id_entorno':
                $query = $CI->db->get($total_tables['entorno']);
                $cadena = "<select name='" . $field . "' id='" . $field . "'>";
                foreach ($query->result_array() as $row) {
                    $cadena .= "<option value='" . $row['id'] . "'>" . $row['descripcion'] . "</option>";
                }
                $cadena .= "</select>";
                return $cadena;
                break;
            case 'fk_id_municipio':
                $query = $CI->db->get_where($total_tables['municipios'], array('fk_id_provincia' => 1));
                $cadena = "<select name='" . $field . "' id='" . $field . "'>";
                foreach ($query->result_array() as $row) {
                    $cadena .= "<option value='" . $row['id'] . "'>" . $row['nombre'] . "</option>";
                }
                $cadena .= "</select>";
                return $cadena;
                break;
            case 'fk_id_users':
                return '<input value="' . $CI->ion_auth->user()->row()->id . '" type="hidden" name="' . $field . '" id="' . $field . '"/>';
                break;
            case 'fk_id_empresa':
                return '<input value="' . $CI->ion_auth->user()->row()->company . '" type="hidden" name="' . $field . '" id="' . $field . '"/>';
                break;
            default:
                return "";
        }
    }

}

if (!function_exists('get_field_usuario')) {
    function get_field_usuario($field = null) {
        $CI = & get_instance();
        $user = $CI->ion_auth->user()->row_array();
        switch ($field) {
            case 'username':
            case 'email':
            case 'email2':
            case 'first_name':
            case 'last_name':
                return '<input value="'.$user[$field].'" type="text" name="' . $field . '" 
                        id="' . $field . '"/>';
                break;
            case 'password':
                $cadena  = '<input value="" class="validate[required,minSize[8]]" type="password" name="' . $field . '" 
                        id="' . $field . '"/>';
                return $cadena;
                break;
            case 'password_confirm':
                $cadena = '<input value="" class="validate[required,equals[password],minSize[8]]" type="password" name="' . $field . '" 
                        id="' . $field . '"/>';
                return $cadena;
                break;
            case 'phone':
                return '<span style="margin-right: 260px"><input value="'.$user[$field].'" maxlength="10" 
                class="class_input_spin spin_input sizew100" type="text" name="' . $field . '" 
                id="' . $field . '" style="margin-right: 0px; padding-right: 0px;"/></span>';
                break;
            case 'idioma':
                $valor = directory_map('./application/language/', 1);
                $cadena = "<select name='" . $field . "' id='" . $field . "'>";
                for($i = 0; $i < count($valor); $i++){
                    if($valor[$i] == $user[$field]){ $seleccionado = "selected"; }else{ $seleccionado = ""; }
                    $cadena .= '<option value="'.$valor[$i].'" '.$seleccionado.'>'.lang($valor[$i]).'</option>';
                }
                $cadena .= "</select>";
                return $cadena;
                break;
            case 'idi_spanish':
                $cadena  = '</div>';
                $cadena .= '<div class="clear"></div>';
                $cadena .= '<div class="grid-10-12"><label>'.lang('idiomas_que_dominas').': </label></div>';
                $cadena .= '<div class="clear"></div>';
                $cadena .= '<div class="grid-2-12"><label>'.lang($field).': <em class="formee-req">*</em></label></div>';
                $cadena .= '<div class="grid-4-12">';
                $cadena .= '<input value="'.$user[$field].'" type="checkbox" name="' . $field . '" 
                id="' . $field . '"/>';
                return $cadena;
                break;
            case 'idi_english':
            case 'idi_german':
            case 'idi_italian':
            case 'idi_french':
            case 'idi_portuguese':
            case 'idi_norwegian':
            case 'idi_swedish':
                $cadena = '<input value="'.$user[$field].'" type="checkbox" name="' . $field . '" 
                id="' . $field . '"/>';
                return $cadena;
                break;
            default:
                return "";
        }
    }

}